package com.daocao.hua.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.Spanned;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.daocao.hua.R;
import com.daocao.hua.adapter.base.ItemAdapter;
import com.daocao.hua.model.MyFundDetailV3Model;
import com.daocao.hua.util.DateTime;
import com.daocao.hua.util.Spans;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class V3MyFundDetailAdapter extends ItemAdapter<MyFundDetailV3Model.DataBean, V3MyFundDetailAdapter.DefaultHolder> {
    private final int x36;
    private final int x24;


    private Context context;

    public V3MyFundDetailAdapter(Context context) {
        super(context);
        this.context = context;
        x36 = context.getResources().getDimensionPixelSize(R.dimen.x36);
        x24 = context.getResources().getDimensionPixelSize(R.dimen.x24);
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_fund_detail, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        MyFundDetailV3Model.DataBean item = getItem(position);
        Spanned txt_left = Spans.with(context).font(item.type_name, x36, 0xff616185).
                font("\n" + DateTime.toFundFormatOne(Long.valueOf(item.create_time) * 1000), x24, 0xffD8DBE9).
                build();
        holder.txtLeft.setText(txt_left);
        holder.txtRight.setText(item.money);
        if(position!=0&&DateTime.toFundFormatTwo(Long.valueOf(item.create_time)*1000).equals(DateTime.toFundFormatTwo(Long.valueOf(getItem(position-1).create_time)*1000))){
            holder.txtTimeTop.setVisibility(View.GONE);
        }else {
            holder.txtTimeTop.setVisibility(View.VISIBLE);
            holder.txtTimeTop.setText(DateTime.toFundFormatTwo(Long.valueOf(item.create_time)*1000));
        }
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_time_top)
        TextView txtTimeTop;
        @BindView(R.id.txt_left)
        TextView txtLeft;
        @BindView(R.id.txt_right)
        TextView txtRight;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
